<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/4/26
 * Time: 15:34
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Distribution extends Base
{
    public function index(){
        if(Request::instance()->isAjax()){
            //男
            $man = Db::table('up_u_user')
                ->field('user_gender, count(user_id) as value')
                ->where('user_gender' , 1)
                ->find();
    
            //女
            $woman = Db::table('up_u_user')
                ->field('user_gender, count(user_id) as value')
                ->where('user_gender', 2)
                ->find();
            $man['name'] = '男';
            $woman['name'] = '女';
    
            unset($man['user_gender']);
            unset($woman['user_gender']);
            $list = [];
            array_push($list, $man);
            array_push($list, $woman);
    
            return json(['sex' => $list]);
        }
        return $this->fetch('distribution/index');
    }
}